home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / MemMgr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.8 KB  |  131 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MemMgr.h
  3.  
  4.     Contains:    Procedural API for memory heaps
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.         
  10. */
  11.  
  12.  
  13. #ifndef _MEMMGR_
  14. #define _MEMMGR_
  15. #pragma once
  16.  
  17. #include <stdlib.h>        // For size_t
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. #pragma lib_export on
  24.  
  25.  
  26. //========================================================================================
  27. // Data types
  28. //========================================================================================
  29.  
  30. typedef char MMBoolean;
  31.  
  32. typedef void* MMBlock;
  33. typedef const void* ConstMMBlock;
  34. typedef void* MMHandle;            // Handles are opaque as in Windows
  35.  
  36. typedef struct MemHeap MemHeap;                    // An opqaue data type
  37.  
  38. typedef enum MMHeapLocation {
  39.     kMMSysMemory,        // Shared system memory, persistent between processes
  40.     kMMAppMemory,        // Process's local memory heap
  41.     kMMTempMemory        // Local process mem outside its heap; may make sense only on Mac
  42. } MMHeapLocation;
  43.  
  44.  
  45. //========================================================================================
  46. // Configuration
  47. //========================================================================================
  48.  
  49. enum{
  50.     kMMDebugConfigMask = 1                // Mask bit for return value from MMConfiguration
  51. };
  52.  
  53. long    MMConfiguration( );
  54.  
  55. //========================================================================================
  56. // Heap management
  57. //========================================================================================
  58.  
  59. MemHeap*    MMNewHeap( MMHeapLocation, size_t initialSize, size_t growBy,
  60.                     const char *name );
  61. void        MMDisposeHeap( MemHeap* );
  62.  
  63. MemHeap*    MMGetDefaultHeap( );
  64. MemHeap*    MMSetDefaultHeap( MemHeap* );                // Returns old default
  65.  
  66. //========================================================================================
  67. // Free space management
  68. //========================================================================================
  69.  
  70. void        MMGetFreeSpace( MemHeap*, size_t *total, size_t *contig );
  71.  
  72. void        MMSystemFreeSpace( MMHeapLocation, size_t *total, size_t *contig );
  73.                 // Total free space in that area of RAM, _not_ MM heap free space.
  74.  
  75. MMBoolean    MMAllocateSlushFund( MemHeap*, size_t size, size_t allocSizeLimit );
  76. size_t        MMSlushFundSize( MemHeap* );                // zero if none
  77. size_t        MMFreeSlushFund( MemHeap* );                // returns size freed
  78.  
  79.  
  80. //========================================================================================
  81. // Operations on pointer based blocks
  82. //========================================================================================
  83.  
  84. MMBlock        MMAllocate( size_t size );
  85. MMBlock        MMAllocateClear( size_t size );
  86.  
  87. MMBlock        MMAllocateIn( size_t size, MemHeap* );
  88. MMBlock        MMAllocateClearIn( size_t size, MemHeap* );
  89.  
  90. MMBlock        MMReallocate( MMBlock, size_t size );
  91. MMBlock        MMSplice( MMBlock, size_t offset, long delta );
  92. void        MMFree( MMBlock );
  93.  
  94. size_t        MMBlockSize( ConstMMBlock );
  95. MemHeap*    MMGetHeap( ConstMMBlock );
  96.  
  97. void        MMSetIsObject( MMBlock, MMBoolean isObject );
  98. MMBoolean    MMIsObject( ConstMMBlock );
  99.  
  100.  
  101. //========================================================================================
  102. // Operations on relocatable blocks (handles)
  103. //========================================================================================
  104.  
  105. MMHandle    MMAllocateHandle( size_t );
  106. MMHandle    MMAllocateHandleIn( size_t, MMHeapLocation );
  107. void        MMFreeHandle( MMHandle );
  108. MMHandle    MMCopyHandle (MMHandle );
  109.  
  110. size_t        MMGetHandleSize( MMHandle );
  111. MMBoolean    MMSetHandleSize( MMHandle, size_t );
  112.  
  113. void*        MMLockHandle( MMHandle );
  114. void        MMUnlockPtr( void* ptr );
  115. void        MMUnlockHandle( MMHandle );
  116.  
  117. //========================================================================================
  118. // Moving memory in general
  119. //========================================================================================
  120.  
  121. void        MMMove( void *dst, const void *src, size_t size );
  122.  
  123.  
  124. #pragma lib_export off
  125.  
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129.  
  130.  
  131. #endif /*_MEMMGR_*/